/*
 * HashRecord.h
 *
 *  Created on: Oct 1, 2011
 *      Author: Belen
 */
#ifndef HASHRECORD_H_
#define HASHRECORD_H_

#include "../BlocksFile.h"
#include "../Block.h"

class HashRecord{

public:
	
	// metodos para logear
	unsigned long size();
	bool getBlockByBlockId(unsigned long id,Block** block);

	/*
	 * Da de alta una clave en el id del bloque correspondiente. 
	 * Devuelve false si no es posible dar de alta (porque est� lleno el bloque) 
	 */
	bool addRecord(unsigned long idBlock, unsigned long idEntity,char* entity,unsigned long longEntity);
	
	bool updateRecord(unsigned long idBlock,unsigned long regKey, char* entity, unsigned long longEntity);
	
	bool removeRecord(unsigned long blockNumber,unsigned long key);
	
	/*
		 * devuelve el numero de bloque que contiene la clave buscada.
		 * Si no encuentra la clave, devuelve -1
		 */
	bool getRecord(unsigned long idBlock,unsigned long regKey, char** data, unsigned long* data_len);

	unsigned long getRecordPosition(unsigned long idBlock,unsigned long regKey);

	bool getNewBlock(unsigned long* newBlockNumber);

	bool getCopyOfBlock(unsigned long blockNumber,Block **block);

	bool removeAllRecordsFromBlock(unsigned long blockNumber);

	HashRecord(string xFilePath, unsigned long xBlockSize);
	virtual ~HashRecord();

	
private:		
	BlocksFile *blocksFile;
	string filePath;
	unsigned long blockSize;
	

};

#endif /*HASHRECORD_H_*/
